﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ApprovalUtilities.Persistence.Database;
using ApprovalUtilities.Utilities;

//download the sample database AdventureWorksLT 
//http://msftdbprodsamples.codeplex.com/wikipage?title=AWLTDocs

namespace DatabaseTest
{
    public class AdventureWorksLTLoader : SqlLoader<Customers[]>
    {
        private readonly int aboveAmount;

        public AdventureWorksLTLoader(int aboveAmount, string connectionString)
            : base(connectionString)
        {
            this.aboveAmount = aboveAmount;
        }

        public override Customers[] Load()
        {
            var insults = DatabaseUtils.Query(GetQuery(), ConnectionString, r=> new Customers()
                                            {FirstName = r.GetString(0),LastName =r.GetString(1)});
            return insults.ToArray();
        }

        public override string GetQuery()
        {
            var sql = @"
                SELECT c.FirstName, c.LastName, getdate()
                FROM saleslt.Customer c JOIN saleslt.SalesOrderHeader soh 
                ON c.CustomerID = soh.CustomerID 
                WHERE soh.TotalDue > {0}".FormatWith(aboveAmount);
            return sql;
        }

}

    public class Customers
    {
        public string LastName { get; set; }
        public string FirstName { get; set; }
        public int CustomerID { get; set; }
    }
}
